package game.hero;


import game.exception.NoEnoughMpException;

public class Magic extends Hero implements IRecover {
	// 体力值上线
	private static final int MAXHP = 100;
	// 魔法上线
	private static final int MAXMP = 200;

	public Magic(String name, int power) {
		super(name, MAXHP, MAXMP, power);
	}

	@Override
	public int attack() {
		int power = getPower() + getWeapon().getAttack();
		System.out.println(getName() + "使用" + getWeapon().getAttack() + "默念咒语进行魔法攻击");
		return power;
	}

	public int fire() throws NoEnoughMpException {
		if (getMp() < 50) {
			throw new NoEnoughMpException("MP不足");
		}

		int random = (int) (Math.random() * 10);
		int basic = getPower() + getWeapon().getAttack();
		System.out.println(getName() + "释放火焰魔法");
		setMp(getMp() - 50);// 扣除mp
		return basic * random;
	}

	@Override
	public int recover() throws NoEnoughMpException {
		int n = 50;
		if (getMp() < 50) {
			throw new NoEnoughMpException("MP不足");
		}
		setHp(getHp() + n);
		if (getHp() > MAXHP) {
			setHp(MAXHP);
		}
		System.out.println(getName() + "对自己释放魔法进行治疗恢复体力");
		setMp(getMp() - n);// 扣除mp
		return n;
	}
}
